package com.group.eams.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.group.eams.pojo.dto.*;
import com.group.eams.pojo.entity.AssetDistribute;
import com.group.eams.pojo.entity.AssetDistribute;
import com.group.eams.pojo.entity.AssetDistribute;
import com.group.eams.pojo.vo.AssetDistributeListVo;
import com.group.eams.pojo.vo.ClaimFixedDetailListVo;
import com.group.eams.pojo.vo.ClaimFixedListVo;
import com.group.eams.service.AssetDistributeService;
import com.group.result.Result;
import com.group.result.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 资产派发表(AssetDistribute)表控制层
 *
 * @author 
 * @since 2024-10-30 12:58:28
 */
@RestController
@RequestMapping("/assetDistribute")
public class AssetDistributeController  {
    /**
     * 服务对象
     */
    @Autowired
    private AssetDistributeService assetDistributeService;

    /**
     * 资产派发信息列表
     * @param AssetDistributeQueryDto
     * @return
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public Result<List<AssetDistributeListVo>> findAssetDistributeByWhere(AssetDistributeQueryDto AssetDistributeQueryDto) {
        Page<AssetDistributeListVo> distributeListVoPage = assetDistributeService.findAssetDistributeByWhere(AssetDistributeQueryDto);
        return Result.buildSuccess(distributeListVoPage.getTotal(), distributeListVoPage.getRecords());
    }

    /**
     * 按id查询资产派发信息
     */
    @RequestMapping(value = "/find", method = RequestMethod.GET)
    public Result<AssetDistribute> find(@RequestParam Long id) {
        AssetDistribute AssetDistribute = assetDistributeService.getById(id);
        return Result.buildSuccess(AssetDistribute);
    }

    /**
     * 查询所有资产派发信息
     */
    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    public Result<List<AssetDistribute>> findAll(){
        List<AssetDistribute> AssetDistributeList = assetDistributeService.list();
        return Result.buildSuccess(AssetDistributeList);
    }

    /**
     * 添加资产派发信息
     */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Result<Object> add(@RequestBody AssetDistribute AssetDistribute) {
        boolean result = assetDistributeService.save(AssetDistribute);
        return result ? Result.buildSuccess() : Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 修改资产派发信息
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public Result<Object> update(@RequestBody AssetDistribute assetDistribute){
        boolean result = assetDistributeService.updateById(assetDistribute);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 批量添加资产派发信息
     */
    @RequestMapping(value = "/batchAdd",method = RequestMethod.POST)
    public Result<Object> batchAdd(@RequestBody List<AssetDistribute> assetDistributes){
        boolean result = assetDistributeService.saveBatch(assetDistributes);
        return result ? Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 批量修改资产派发信息
     */
    @RequestMapping(value = "/batchUpdate",method = RequestMethod.POST)
    public Result<Object> batchUpdate(@RequestBody List<AssetDistribute> assetDistributes){
        boolean result = assetDistributeService.updateBatchById(assetDistributes);
        return result ? Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 批量移除资产派发信息
     */
    @RequestMapping(value = "/batchRemove",method = RequestMethod.POST)
    public Result<Object> batchRemove(@RequestBody List<Long> ids){
        boolean result = assetDistributeService.removeByIds(ids);
        return result ? Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 查询所有闲置资产信息
     */
    @RequestMapping(value = "/findClaimFixed",method = RequestMethod.GET)
    public Result<List<ClaimFixedListVo>> findClaimFixed(FixedAssetQueryDto fixedAssetQueryDto){
        Page<ClaimFixedListVo> claimFixedListVoPage = assetDistributeService.findClaimFixedByWhere(fixedAssetQueryDto);
        return Result.buildSuccess(claimFixedListVoPage.getTotal(), claimFixedListVoPage.getRecords());
    }

    /**
     * 根据选择的id查询资产
     */
    @RequestMapping(value = "/addClaimFixedDetail",method = RequestMethod.POST)
    public Result<List<ClaimFixedDetailListVo>> addClaimFixedDetail(@RequestBody AssetPartDto assetPartDto){
        System.out.println(assetPartDto.getAssetIds());
        Page<ClaimFixedDetailListVo> claimFixedDetailListVoPage = assetDistributeService.addClaimFixedDetail(assetPartDto);
        return Result.buildSuccess(claimFixedDetailListVoPage.getTotal(), claimFixedDetailListVoPage.getRecords());
    }


    /**
     * 按申请单号查询资产申领表下的所有资产信息"
     */
    @RequestMapping(value = "/findClaimFixedDetail",method = RequestMethod.GET)
    public Result<List<ClaimFixedDetailListVo>> findClaimFixedDetail(ApplyNumFixedAssetQueryDto applyNumFixedAssetQueryDto){
        Page<ClaimFixedDetailListVo> claimFixedDetailListVoPage = assetDistributeService.findClaimFixedDetail(applyNumFixedAssetQueryDto);
        return Result.buildSuccess(claimFixedDetailListVoPage.getTotal(), claimFixedDetailListVoPage.getRecords());
    }

    /**
     * 根据申请单号和assetId删除
     */
    @RequestMapping(value = "/deleteByAssetIds", method = RequestMethod.POST)
    public Result<Object> batchDeleteByAssetIds(@RequestBody BatchDeleteIdsDto batchDeleteIdsDto){
        int result = assetDistributeService.deleteByApplicationNum(batchDeleteIdsDto);
        return result > 0 ? Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 根据申请单号和assetId修改
     */
    @RequestMapping(value = "/updateByAssetIds", method = RequestMethod.POST)
    public Result<Object> batchDeleteByAssetIds(@RequestBody BatchUpdateIdsDto<AssetDistribute> batchUpdateIdsDto){
        int result = assetDistributeService.updateByApplicationNum(batchUpdateIdsDto);
        return result > 0 ? Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 根据申请单号查询
     */
    @RequestMapping(value = "/findByNum",method = RequestMethod.GET)
    public Result<AssetDistribute> findByNum(@RequestParam String applicationNum) {
        AssetDistribute assetDistribute = assetDistributeService.findDistributeByNum(applicationNum);
        return Result.buildSuccess(assetDistribute);
    }
    
}

